import { createRouter, createWebHistory } from "vue-router"
import pinia from '../store'
import { useRouterStore, useIndexStore } from "../store/path"
const routerStore = useRouterStore(pinia)
const indexStore = useIndexStore(pinia)
const index = () => import("@/view/index/index.vue")
const lists = () => import("@/view/lists/index.vue")
const notFound = () => import("@/view/notFound/index.vue")

const routes = [
    {
        path: "/",
        component: index
    },
    {
        path: "/lists",
        component: lists
    },
    {
        path: '/404',
        name: '404',
        component: notFound
    },
    {
        path: '/:pathMatch(.*)',
        redirect: '/404'
    }
]


const router = createRouter({
    history: createWebHistory(),
    linkActiveClass: 'active',
    routes: routes,
    scrollBehavior() {
        return { top: 0 }
    },
})
router.beforeEach((to, from, next) => {
    routerStore.$patch({
        currentPage: to.name
    })
    // indexStore.$patch({
    //     showLoading: true
    // })
    next()
})
export default router